package _base0to1;

import java.util.ArrayList;
import java.util.List;

/**
 * 1472. 设计浏览器历史记录
 */
public class No1472 {
    private int curIndex;
    private int lastIndex;
    private final List<String> historyUrl;

    public No1472(String homepage) {
        this.historyUrl = new ArrayList<>();
        historyUrl.add(homepage);
        this.curIndex = 0;
        this.lastIndex = 0;
    }

    public void visit(String url) {
        this.curIndex++;
        this.lastIndex = this.curIndex;
        historyUrl.add(this.curIndex, url);
    }

    public String back(int steps) {
        this.curIndex = Math.max(this.curIndex - steps, 0);
        return historyUrl.get(this.curIndex);
    }

    public String forward(int steps) {
        this.curIndex = Math.min(this.curIndex + steps, this.lastIndex);
        return historyUrl.get(this.curIndex);
    }
}
